<template>
  <div>
    <!--列表-->
    <el-table
      ref="table"
      v-loading="tableLoad"
      :data="tableData"
      tooltip-effect="dark"
      fit
      highlight-current-row
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55"> </el-table-column>
      <el-table-column prop="sampleNum" label="样品编号"> </el-table-column>
      <el-table-column prop="orderNum" label="委托单号"> </el-table-column>
      <el-table-column prop="sampleName" label="样品名称"> </el-table-column>
      <el-table-column prop="inspectedUnit" label="受检单位"> </el-table-column>
      <el-table-column prop="detectionItemName" label="检测项目" />
      <el-table-column
        v-if="systemType == 'cdc'"
        prop="samplingDateTime"
        label="采样日期"
      />
      <el-table-column label="操作" width="140">
        <template slot-scope="{ row }">
          <div class="base-table-operation">
            <el-link v-rights="'Add'" type="primary" @click="receiving(row)"
              >接收</el-link
            >
          </div>
        </template>
      </el-table-column>
    </el-table>
    <!--分页
    <BasePagination
      :total="pagination.total"
      :current-page="pagination.pageIndex"
      :page-count="pagination.pageCount"
      @changePage="changePage"
    /-->
    <!-- 样品接收 -->
    <!-- <SampleReceivingDialog
      ref="SampleReceivingDialog"
      :dialog-form-visible.sync="dialogFormVisible"
      :row-data.sync="rowData"
      :system-type.sync="systemType"
      @closeSampleReceivingDialog="closeSampleReceivingDialog"
    /> -->

    <SampleReceivingEdit
      v-if="dialogFormVisible"
      :dialog-form-visible.sync="dialogFormVisible"
      :row-data.sync="rowData"
      @closeSampleReceivingDialog="closeSampleReceivingDialog"
    />
  </div>
</template>

<script>
import { shortTime } from "../../../utils/moment.js";
// import SampleReceivingDialog from "./SampleReceivingDialog.vue";
import SampleReceivingEdit from "./SampleReceivingEdit.vue";
import { SampleReceivingPendingGetList } from "../../../api/SampleManage/SampleReceiving";
export default {
  name: "SampleReceivingCommission",
  components: {
    // SampleReceivingDialog,
    SampleReceivingEdit,
  },
  props: {
    systemType: {
      type: String,
      default: "",
    },
    loadState: {
      type: Boolean,
      default: false,
    },
    filterForm: {
      type: Object,
      default() {},
    },
    pagination: {
      type: Object,
      default() {
        return { pageIndex: 1, pageSize: 10 };
      },
    },
  },
  data() {
    return {
      readOnly: false,
      dialogFormVisible: false,
      loading: false,
      // 样品登记id
      sampleRegistrationId: "",
      tableLoad: false,
      tableData: [],
      tableDatas: [],
      rowData: [],
    };
  },
  computed: {},
  watch: {
    loadState(val) {
      if (val) {
        this.getList();
      }
    },
    "pagination.pageIndex"(newV, oldV) {
      this.getList();
    },
  },
  created() {
    this.getList();
  },
  methods: {
    // 关闭样品接收dialog
    closeSampleReceivingDialog() {
      this.rowData = [];
      this.getList();
    },
    // 接收
    receiving(row) {
      this.rowData.push(row);
      this.dialogFormVisible = true;
    },
    // 查看
    selUnit(row) {
      this.sampleRegistrationId = row.id;
      this.readOnly = true;
      this.dialogFormVisible = true;
    },
    handleSelectionChange(val) {
      this.tableDatas = val;
    },
    getList(flag) {
      if (flag) {
        this.pagination.pageIndex = 1;
      }
      this.loading = true;
      SampleReceivingPendingGetList({ ...this.filterForm, ...this.pagination })
        .then((res) => {
          this.tableData = res.data.dataList ? res.data.dataList : [];
          for (let i = 0; i < this.tableData.length; i++) {
            this.tableData[i].receivingDate = shortTime(new Date());
          }
          this.pagination.total = res.data.total;
          this.$emit("update:total", res.data.total);
          this.loading = false;
        })
        .catch(() => {
          this.loading = false;
        });
    },
  },
};
</script>
